﻿function bindElementClickEvent(ths, fun) {
    ths.off("touchstart");
    ths.on("touchstart",
        function (event) {
            //只有1的时候或者0的时候才触发
            G_CLICKSSTATUS = 1;
            event.stopPropagation();
        });

    ths.off("touchmove");
    ths.on("touchmove",
        function (event) {
            //拖动的时候不要触发
            G_CLICKSSTATUS = 2;
            event.stopPropagation();
        });

    ths.off(G_CLICK);

    ths.on(G_CLICK, function(event){
        event.stopPropagation();
        if(G_CLICKSSTATUS != 2)
            fun(event);
    });
}

//所有对象的click事件
function elementClickEvent(event)
{
    var ths = $(event.target);
    if (!checkElementClick(ths)) {
        //如果触发的是同一个东西，不再重复触发
        if (ths == G_CLICKELEMENT) return;

        getTools().hide();
        removeBgColor();

        G_CLICKELEMENT = ths;
        showMenu();
    }
}

//绑定按钮信息
function bindButtonClickEvent() {
    bindElementClickEvent($(".adbtn,.adbtnX"), function (event) {
        var ths = $(event.target);
        var fun = ths.attr("data-f") || "";
        if (fun != "") eval(fun);
    });

    $("input[type='file']").unbind("change");
    $("input[type='file']").bind("change", uploadfile);
}

//判断是否允许点击
function checkElementClick(obj) {
    //判断是不是点击到dz上面，如果是动作上面，就不要阻止事件
    return obj && obj.length>0 && obj.hasClass("d_z");// && getMenu() && getMenu().length > 0;
}